package com.example.xd.fmpeg_test;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.xd.fmpeg_test.adater.FilterAdapter;

import java.util.ArrayList;
import java.util.List;

public class FilterActivity extends AppCompatActivity implements BaseQuickAdapter.OnItemClickListener {

    private RecyclerView mFilter_recycle;
    ArrayList<FilterBean> filterBeans = new ArrayList<>();
    private List<String> mFilter = new ArrayList<>();
    private List<String> mFilterimage;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_filter);
        mFilter_recycle = findViewById(R.id.filter_recycle);
        mFilter_recycle.setLayoutManager(new GridLayoutManager(this, 4));
        FilterAdapter filterAdapter = new FilterAdapter(this, R.layout.filter_item, filterBeans);
        mFilter_recycle.setAdapter(filterAdapter);
        filterAdapter.setOnItemClickListener(this);
        mFilterimage = AssetsUtil.getAssetFileList(this, "filterimage");

        mFilter.add("lutyuv=y=maxval+minval-val:u=maxval+minval-val:v=maxval+minval-val");
        mFilter.add("lutyuv=y=maxval+minval-val:u=maxval+minval-val:v=maxval+minval-val");
        mFilter.add("lutyuv=y=negval:u=negval:v=negval");
        mFilter.add("lutyuv=y=negval");
        mFilter.add("lutyuv=u=128:v=128");
        mFilter.add("lutyuv=y=2*val");
        mFilter.add("lutyuv=y=gammaval(0.5)");
        mFilter.add("lutyuv=y='bitand(val, 128+64+32)'");
        mFilter.add("lutyuv=u=128:v=128");
        mFilter.add("lutyuv=y=2*val");
        mFilter.add("lutyuv=y=gammaval(0.5)");
        mFilter.add("lutyuv=y='bitand(val, 128+64+32)'");

        FilterBean filterBean;
        for (int i = 0; i < mFilter.size(); i++) {
            filterBean = new FilterBean(mFilter.get(i), mFilterimage.get(i));
            filterBeans.add(filterBean);
        }
        filterAdapter.notifyDataSetChanged();
    }

    @Override
    public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
        Intent intent = new Intent();
        intent.putExtra("filter_path", mFilter.get(i));
        setResult(RESULT_OK, intent);
        finish();
    }
}
